package wuke.show;

import java.util.ArrayList;
import java.util.List;

import wuke.model.Contact;
import wuke.test.R;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ImageAdapter extends BaseAdapter {

	private Context mContext;

	private List<Contact> mContacts = new ArrayList<Contact>();

	public List<Contact> getmContacts() {
		return mContacts;
	}

	public void setmContacts(List<Contact> mContacts) {
		this.mContacts = mContacts;
	}

	public ImageAdapter(Context context) {
			this.mContext = context;
	}

	@Override
	public int getCount() {

		return mContacts.size();

	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		

		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		ViewGroup myView = (ViewGroup) inflater.inflate(R.layout.person,null ,true);
		myView.setPadding(0,0,0, 0);
		

		ImageView imageView = (ImageView) myView.getChildAt(0);
		imageView.setPadding(0,0,0,0);
		
		
		TextView  textView = (TextView) myView.getChildAt(1);

		String photoURI = mContacts.get(position).getPhotoURI();
		String strName = mContacts.get(position).getName();

		if (photoURI != null) {
			imageView.setImageURI(Uri.parse(photoURI));
		}else{
			imageView.setImageResource(R.drawable.photo);
		}
		
		if(strName==null){
			textView.setText("anonymity");
		}else{
			textView.setText(strName);
		}
		
		

		return myView;
	}

}
